/*
 * Copyright 2009 Thor Hovden
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the
 * License. 
 */
package dev.sketch;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import eviva.structure.MissionControl;

/**
 * A frame to display stuff in
 * 
 * @author Thor Hovden
 */
public class Face extends JFrame {

	/** Java required serialization key */
	private static final long serialVersionUID = -6245484277505949406L;

	/**
	 * Create face
	 * 
	 * @param mission
	 * @param windowname
	 * @param actions
	 */
	public Face(MissionControl mission, String windowname, Action... actions) {
		super(windowname);
		MissionControl.Mission m3 = mission.set(3, "Display");
		setMinimumSize(new Dimension(400, 200));
		setSize(new Dimension(800, 400));
		setLocation(50, 200);
		for (Action action : actions) {
			if (action.getType() == Action.Type.DISPLAY) {
				JTextArea ta = new JTextArea(action.getText());
				setCorrectFontSize(ta);
				JScrollPane sp = new JScrollPane(ta);
				getContentPane().add(BorderLayout.CENTER, sp);
			}
		}
		setVisible(true);

	    mission.complete(m3);
	}

	private void setCorrectFontSize(JComponent c) {
	    int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
	    int fontSize = (int)Math.round(12.0 * screenRes / 72.0);

	    Font font = new Font("Arial", Font.PLAIN, fontSize);
	    c.setFont(font);
	    //c.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
}
